﻿using System;
using System.Text;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Item;
using Demo_G.O.S.E.ServerEngine.Util;
using System.Diagnostics;

namespace Demo_G.O.S.E.ServerEngine.Treasure
{
    /// <summary>
    /// 
    /// </summary>
    public class BaseTreasure
    {
        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        /// <param name="loot"></param>
        /// <param name="probability"></param>
        public BaseTreasure( Loot[] loot, float probability )
        {
            m_Loots = loot;
            m_fProbability = probability;
        }
        #endregion

        #region zh-CHS 属性 | en Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Loot[] m_Loots;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public Loot[] Loots
        {
            get { return m_Loots; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private float m_fProbability;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public float Probability
        {
            get { return m_fProbability; }
        }
        #endregion

        #region zh-CHS 静态属性 | en Static Properties
        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static float s_DropMultiplier = 1f;
        #endregion
        /// <summary>
        /// 道具掉落的几率比率
        /// </summary>
        public static float DropMultiplier
        {
            get { return BaseTreasure.s_DropMultiplier; }
            set { BaseTreasure.s_DropMultiplier = value; }
        }

        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static long s_DropGoldMultiplier = 1;
        #endregion
        /// <summary>
        /// 金币掉落的几率比率
        /// </summary>
        public static long DropGoldMultiplier
        {
            get { return BaseTreasure.s_DropGoldMultiplier; }
            set { BaseTreasure.s_DropGoldMultiplier = value; }
        }
        #endregion

        #region zh-CHS 方法 | en Method
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsDrop()
        {
            if ( Utility.RandomDouble() * 100 < m_fProbability * BaseTreasure.s_DropMultiplier )
                return true;
            else
                return false;
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private List<BaseItem> m_Treasure = new List<BaseItem>();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lootMoney"></param>
        /// <returns></returns>
        public BaseItem[] RandomDrop()
        {
            if ( m_Loots == null )
            {
                Debug.WriteLine( "BaseTreasure.RandomDrop(...) - m_Loots == null error!" );
                return null;
            }

            m_Treasure.Clear();

            foreach ( Loot loot in m_Loots )
            {
                if ( Utility.RandomDouble() * 100 < loot.Probability * BaseTreasure.s_DropMultiplier )
                {
                    BaseItem l_BaseItem = loot.Instance();
                    if ( l_BaseItem == null )
                        Debug.WriteLine( "BaseTreasure.RandomDrop(...) - l_BaseItem == null error!" );
                    else
                        m_Treasure.Add( l_BaseItem );
                }
            }

            return m_Treasure.ToArray();
        }
        #endregion
    }
}

